/**
 * Created by Administrator on 2017/8/29.
 */
var pageSize=10;
var pages=0;
var cont=1;
var time=Date.parse(new Date())/1000;
console.log(time);
function getActi() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get"),
        data:{
            page_size:pageSize,
            page_num:1,
            type:1,
            timestamp:time
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas);
            //soll=true;
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            if(pages>0){
                $(".nmts").hide();
            }
            var strs="";
            $.each(arr,function (i,el) {
                var time=new Date(parseInt(arr[i].start_time) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ').substring(0,10)
                strs+=` <div class="m-market-activity" data-url="`+el.redirect_url+`"  data-id=`+el.activity_id+`  onclick="getAcInfo(this)">
                            <div class="content">
                                <div class="progress `+C(arr[i].activity_status)+`">`+Wz(arr[i].activity_status)+`</div>
                                     <div class="imgbox" style="background-image: url(`+arr[i].logo_url+`)"></div>
                                <div class="info">
                                    <div class="title">
                                        `+arr[i].name+`
                                    </div>
                                    <div class="date">
                                        `+time+`
                                    </div>
                                </div>
                            </div>
                        </div>`
            });
            $(strs).appendTo("#list");

            $("#loading").hide();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
getActi();
function C(s) {
    if(s=="1"){
        return "in"
    }else {
        return "";
    }
}
function Wz(s) {
    if(s=="1"){
        return "报名中"
    }else {
        return "已结束";
    }
}
function gcscroll(obj) {
    var $this =$(obj),
        viewH =$this.height(),//可见高度
        contentH =$this.get(0).scrollHeight,//内容高度
        scrollTop =$this.scrollTop();//滚动高度
    if(contentH - viewH - scrollTop <=1) { //到达底部100px时,加载新内容
        //console.log(cont);
        var nowpage=pages%pageSize==0?(pages/pageSize):(Math.floor(pages/pageSize)+1);
        if(nowpage===cont){
            return false
        }
        //alert("1111")
        cont+=1;
        console.log(cont);
        showToast();
        xlgetActi()
    }
}

function xlgetActi() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/activity/get"),
        data:{
            user_id:"1",
            page_size:pageSize,
            type:1,
            page_num:cont,
            timestamp:time
        },
        // contentType : "application/json",
        success : function(datas) {
            console.log(datas);
            //soll=true;
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            var strs="";
            $.each(arr,function (i,el) {
                var time=new Date(parseInt(arr[i].start_time) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ').substring(0,10)
                strs+=` <div class="m-market-activity" data-url=`+arr[i].redirect_url+` data-id=`+arr[i].activity_id+` onclick="getAcInfo(this)">
                            <div class="content">
                                <div class="progress `+C(arr[i].activity_status)+`">`+Wz(arr[i].activity_status)+`</div>
                                     <div class="imgbox" style="background-image: url(`+arr[i].logo_url+`)"></div>
                                <div class="info">
                                    <div class="title">
                                        `+arr[i].name+`
                                    </div>
                                    <div class="date">
                                        `+time+`
                                    </div>
                                </div>
                            </div>
                        </div>`
            });
            $(strs).appendTo("#list");
            hideToast();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
function showToast() {
    $("#loadingToast").show()
}
function hideToast() {
    $("#loadingToast").hide();
}
function getAcInfo(obj){
    var $this=$(obj);
    var id=$this.attr("data-id");
    var url=$this.attr("data-url");
    //console.log(id+url)
   window.location.href="gfactivitiesing.html?id="+id+"&url="+url
}
